package main;

import java.awt.CardLayout;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

public class PresentationFrame extends JFrame implements ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JPanel p;
	private int screenWidth = 600;
	private int screenHeight = 600;
	private JLabel imageComponent;
	/**
	 * 
	 * @throws HeadlessException
	 */
	public PresentationFrame() throws HeadlessException {
		// TODO Auto-generated constructor stub
		constructFrame();
	}

	/**
	 * 
	 * @param gc
	 */
	public PresentationFrame(GraphicsConfiguration gc) {
		super(gc);
		// TODO Auto-generated constructor stub
		constructFrame();
	}

	/**
	 * 
	 * @param title
	 * @throws HeadlessException
	 */
	public PresentationFrame(String title) throws HeadlessException {
		super(title);
		// TODO Auto-generated constructor stub
		constructFrame();
	}

	/**
	 * 
	 * @param title
	 * @param gc
	 */
	public PresentationFrame(String title, GraphicsConfiguration gc) {
		super(title, gc);
		// TODO Auto-generated constructor stub
		constructFrame();
	}

	/**
	 * 
	 */
	public void constructFrame() {
		setSize(screenWidth, screenHeight);
		
		CardLayout cl = new CardLayout();
		setLayout(cl);

		p = new JPanel();
		setContentPane(p);
		
		imageComponent = new JLabel("", JLabel.CENTER);
		p.add(imageComponent);

		createMenuBar();

		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation(dim.width/2 - getWidth()/2, dim.height/2 - getHeight()/2);

		ImageIcon image = new ImageIcon("src/drone.png");
		setIconImage(image.getImage());

		setVisible(true);
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
	}

	/**
	 * 
	 */
	public void createMenuBar() {
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		JMenu fichier = new JMenu("Fichier");
		menuBar.add(fichier);

		JMenuItem quitter = new JMenuItem("Quitter");
		fichier.add(quitter);
		quitter.setActionCommand("Quitter");
		quitter.addActionListener(this);

		JMenu importer = new JMenu("Importer");
		menuBar.add(importer);

		JMenuItem image = new JMenuItem("Image");
		importer.add(image);
		image.setActionCommand("Image");
		image.addActionListener(this);
		
		JMenuItem donnees = new JMenuItem("Données");
		importer.add(donnees);
		donnees.setActionCommand("Donnees");
		donnees.addActionListener(this);
		
		JMenuItem video = new JMenuItem("Vidéo");
		importer.add(video);
		video.setActionCommand("Video");
		video.addActionListener(this);
		
		JMenu live = new JMenu("Vidéo en direct");
		menuBar.add(live);
		live.setActionCommand("Live");
		live.addActionListener(this);
	}

	/**
	 * 
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if (e.getActionCommand().equals("Quitter")){ 
			System.exit(0);
		}

		else if (e.getActionCommand().equals("Image")){
			JFileChooser dialogue = new JFileChooser();
			dialogue.showOpenDialog(null);
			File result = dialogue.getSelectedFile();
			ImageIcon image = new ImageIcon(result.getPath());
			imageComponent.setIcon(image);
		}
		
		else if (e.getActionCommand().equals("Donnees")) {
			System.exit(0);
		}
		
		else if (e.getActionCommand().equals("Video")) {
			JFileChooser dialogue = new JFileChooser();
			dialogue.showOpenDialog(null);
			File result = dialogue.getSelectedFile();
			ShowVideo sv = new ShowVideo(result);
		}
		
		else if (e.getActionCommand().equals("Live")) {
			ShowVideo sv = new ShowVideo();
		}
	}

}
